package gdut.stream.middle;

import java.util.ArrayList;
import java.util.List;

public class LimitTest {
    public static void main(String[] args) {
        List<Student> students = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            Student student = new Student(i, "student" + i);
            students.add(student);
        }
        students.stream()
                .sorted((student1, student2) -> student2.getAge() - student1.getAge())
                .limit(2)
                .forEach(student -> System.out.println(student));
    }
}
